package com.will.weiyuekotlin.ui.weather.presenter


import com.will.weiyuekotlin.bean.WeatherBean
import com.will.weiyuekotlin.net.BaseObserver
import com.will.weiyuekotlin.net.WeatherApi
import com.will.weiyuekotlin.ui.base.BasePresenter
import com.will.weiyuekotlin.ui.news.contract.WeatherContract
import com.will.weiyuekotlin.utils.applySchedulers
import javax.inject.Inject


/**
 * desc: .
 * author: Will .
 * date: 2017/12/8 .
 */
class WeatherPresenter @Inject
constructor(private var mNewsApi: WeatherApi) : BasePresenter<WeatherContract.View>(), WeatherContract.Presenter {

    override fun getData(province: String, city: String, county: String) {
        mNewsApi.getWeather(province, city, county)
                .applySchedulers()
                .compose(mView?.bindToLife<WeatherBean>())
                .subscribe(object : BaseObserver<WeatherBean>() {
                    override fun onSuccess(t: WeatherBean?) {
                        mView?.loadData(t)
                    }

                    override fun onFail(e: Throwable) {
                        mView?.loadData(null)
                    }
                })

    }

}
